home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / utils / copyobj / textobj.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  2.4 KB  |  109 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <libraries/dos.h>
  4. #include <workbench/workbench.h>
  5. #include <workbench/startup.h>
  6.  
  7. #include <clib/alib_protos.h>
  8. #include <clib/exec_protos.h>
  9. #include <clib/dos_protos.h>
  10. #include <clib/icon_protos.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. struct Library *IconBase=NULL;
  15. void sr(char *s);
  16.  
  17. char source[200];
  18. char destination[200];
  19. char itype[200];
  20. UBYTE tooltype[102][100];
  21. char toolfilename[200];
  22. void InitTypes(char *s);
  23.  UBYTE *tools[102];
  24.  
  25. main(int argc,char *argv[])
  26. {
  27.   char *s;
  28.   int i;
  29.   UBYTE mytype;
  30.   struct DiskObject *src;
  31.   struct DiskObject *dst;
  32.   struct Gadget *srcgad;
  33.   struct DiskObject new;
  34.   BOOL success=FALSE;
  35.   for(i=0;i<100;i++)
  36.      tools[i]=&tooltype[i];
  37.   if(argc!=2)
  38.   {
  39.      printf("TextObj version 1.0, written by Joseph Hodge\n");
  40.      printf("usage: TextObj <source.txt>\n");
  41.      printf("   ie: TextObj Serial.txt\n");
  42.      printf("\n");
  43.      printf("\n\n");
  44.      exit(0);
  45.   }
  46.   strcpy(source,argv[1]);
  47.   strcpy(destination,source);
  48.   sr(source);
  49.   sr(destination);
  50.   InitTypes(source);
  51.   i=strlen(destination)-1;
  52.   while(i>=0)
  53.   {
  54.      if(destination[i]=='.') break;
  55.      i--;
  56.   }
  57.   if(i) destination[i]='\0';
  58.  
  59.   IconBase=OpenLibrary("icon.library",0L);
  60.   if(src=GetDiskObject(destination))
  61.   {
  62.  
  63.     srcgad=(struct Gadget *)&src->do_Gadget;
  64.        CopyMem(src,&new,sizeof(struct DiskObject));
  65.        new.do_Gadget.Width=srcgad->Width;
  66.        new.do_Gadget.Height=srcgad->Height;
  67.        new.do_Gadget.Flags=srcgad->Flags;
  68.        new.do_Gadget.Activation=srcgad->Activation;
  69.        new.do_Gadget.GadgetType=srcgad->GadgetType;
  70.        new.do_Gadget.GadgetRender=srcgad->GadgetRender;
  71.        new.do_Gadget.SelectRender=srcgad->SelectRender;
  72.        new.do_ToolTypes=(APTR)tools;
  73.        new.do_Type= src->do_Type;
  74.        PutDiskObject(destination,(struct DiskObject *)&new);
  75.     FreeDiskObject(src);
  76.     DeleteFile(source);
  77.   }
  78.   CloseLibrary(IconBase);
  79.   exit(0);
  80. }
  81. void InitTypes(char *s)
  82. {
  83.    FILE *fi;
  84.    register int i=0;
  85.    int j=0;
  86.    char image[102];
  87.    fi=fopen(s,"r");
  88.    if(fi!=NULL)
  89.    {
  90.      while(fgets(image,100,fi)!=NULL && i<100)
  91.      {
  92.         sr(image); strcpy(&tooltype[i][0],image);
  93.         i++;
  94.      }
  95.      fclose(fi);
  96.    }
  97.    tools[i]=NULL;
  98. }
  99. void sr(char *s)
  100. {
  101.    register int i;
  102.    i=strlen(s)-1;
  103.    while(i>-1)
  104.    {
  105.      if(*(s+i)<=32) *(s+i)='\0'; else break;
  106.      i--;
  107.    }
  108. }
  109.